package com.gs.login.controller;

import com.gs.login.domain.User;
import com.gs.login.service.UserSevice;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

/**
 * @Description
 * @Author heartstring
 * @Date 2020/5/21
 */
@Slf4j
@RestController
public class LoginController {

    @Autowired
    private UserSevice userSevice;

    @Autowired
    private PasswordEncoder passwordEncoder;

    @RequestMapping("/add")
    public User addUser()
    {
        User user =new User();
        user.setUserName("gs");
        user.setPassword("12345677898");
        user.setUid(UUID.randomUUID().toString());
        userSevice.addUser(user);
        return user;
    }

    @RequestMapping("/register")
    public User register(@RequestParam("username") String username, @RequestParam("username")String password)
    {
        log.info("userName = {}，password = {}",username,password);
        User user =new User();
        user.setUserName(username);
        user.setPassword(passwordEncoder.encode(password));
        user.setUid(UUID.randomUUID().toString());
        userSevice.addUser(user);
        return user;
    }


}
